package com.fudan.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.fudan.dao.RoomDaoImpl;
import com.fudan.dto.entities.Room;
import com.fudan.dto.entities.User;

@Transactional
@Service
public class RoomServiceImpl {
	
	@Autowired
	private UserServiceImpl userService;
	
	@Autowired
	private QuestionServiceImpl questionService;
	
	@Autowired
	private RoomDaoImpl roomDao;
	
	public List<Room> getAllRooms(){
		return roomDao.getAllRooms();
	
	}
	
	public Room getRoom(Integer roomId){
		Room room = roomDao.getRoomId(roomId);
		return room;
	}
	
	public Room createRoom(String roomName, String userId){
		User user = userService.getUser(new Integer(userId));
		Room room = new Room(roomName, user);
		room = roomDao.save(room);
		return room;
	}
	
	public Room updateRoom(Room room){
		room = roomDao.save(room);
		return room;
	}
	

}
